﻿#region Copyrigth and License
/*==============================================================================
 *  Copyright (c) cndotnet.org Corporation.  All rights reserved.
 * ===============================================================================
 * This code and information is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the implied warranties
 * of merchantability and fitness for a particular purpose.
 * ===============================================================================
 * Licensed under the GNU General Public License (GPL) v2
 * http://www.cndotnet.org/ucenter
 * ==============================================================================*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using UCenter.Core.Model;

namespace UCenter.Models
{
    [Table(Name = "dbo.VerifyCode")]
    public class VerifyCode : EntityBase
    {
        #region Private Fields

        private int _Id;

        private int _userId;

        private int _codeType;

        private string _code;

        private DateTime _createDate;

        private DateTime? _sendDate;

        private DateTime _expireDate;

        private EntityRef<User> _user;

        #endregion

        #region Constructor

        public VerifyCode()
        {
            this._user = default(EntityRef<User>);
        }

        #endregion

        #region Public Properties

        [Column(Name = "ID", Storage = "_Id", DbType = "Int NOT NULL", IsPrimaryKey = true, IsDbGenerated = true)]
        public int ID
        {
            get
            {
                return this._Id;
            }
            set
            {
                if (this._Id != value)
                {
                    this.SendPropertyChanging("ID");
                    this._Id = value;
                    this.SendPropertyChanged("ID", value);
                }
            }
        }

        [Column(Name = "UserId", Storage = "_userId", DbType = "Int NOT NULL")]
        public int UserId
        {
            get
            {
                return this._userId;
            }
            set
            {
                if (this._userId != value)
                {
                    if (this._user.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging("UserId");
                    this._userId = value;
                    this.SendPropertyChanged("UserId", value);
                }
            }
        }

        [Column(Name = "CodeType", Storage = "_codeType", DbType = "Int NOT NULL")]
        public int CodeType
        {
            get
            {
                return this._codeType;
            }
            set
            {
                if (this._codeType != value)
                {
                    this.SendPropertyChanging("CodeType");
                    this._codeType = value;
                    this.SendPropertyChanged("CodeType", value);
                }
            }
        }

        [Column(Name = "VerifyCode", Storage = "_code", DbType = "VarChar(128) NOT NULL", CanBeNull = false)]
        public string Code
        {
            get
            {
                return this._code;
            }
            set
            {
                if (this._code != value)
                {
                    this.SendPropertyChanging("Code");
                    this._code = value;
                    this.SendPropertyChanged("Code", value);
                }
            }
        }

        [Column(Name = "CreateDate", Storage = "_createDate", DbType = "DateTime NOT NULL")]
        public DateTime CreateDate
        {
            get
            {
                return this._createDate;
            }
            set
            {
                if (this._createDate != value)
                {
                    this.SendPropertyChanging("CreateDate");
                    this._createDate = value;
                    this.SendPropertyChanged("CreateDate", value);
                }
            }
        }

        [Column(Name = "SendDate", Storage = "_sendDate", DbType = "DateTime")]
        public DateTime? SendDate
        {
            get
            {
                return this._sendDate;
            }
            set
            {
                if (this._sendDate != value)
                {
                    this.SendPropertyChanging("SendDate");
                    this._sendDate = value;
                    this.SendPropertyChanged("SendDate", value);
                }
            }
        }

        [Column(Name = "ExpireDate", Storage = "_expireDate", DbType = "DateTime NOT NULL")]
        public DateTime ExpireDate
        {
            get
            {
                return this._expireDate;
            }
            set
            {
                if (this._expireDate != value)
                {
                    this.SendPropertyChanging("ExpireDate");
                    this._expireDate = value;
                    this.SendPropertyChanged("ExpireDate", value);
                }
            }
        }

        [Association(Name = "User_VerifyCode", Storage = "_user", ThisKey = "UserId", IsForeignKey = true)]
        public User User
        {
            get
            {
                return this._user.Entity;
            }
            set
            {
                User previousValue = this._user.Entity;
                if (((previousValue != value)
                            || (this._user.HasLoadedOrAssignedValue == false)))
                {
                    if ((previousValue != null))
                    {
                        this._user.Entity = null;
                        previousValue.VerifyCodes.Remove(this);
                    }
                    this._user.Entity = value;
                    if ((value != null))
                    {
                        value.VerifyCodes.Add(this);
                        this._userId = value.ID;
                    }
                    else
                    {
                        this._userId = default(int);
                    }
                }
            }
        }

        #endregion
    }
}
